---
sidebar_position: 2
---

import CodeBlock from "@theme/CodeBlock";
import ExampleOpenAI from "@examples/openai-completion-example/openai_completion_example.go";

# Quickstart: LangChainGo with OpenAI

Get started by running your first program with LangChainGo and [OpenAI](https://openai.com/). OpenAI's GPT models are renowned for their proficiency and expansive capabilities.

## Prerequisites

1. **OpenAI API Key**: Sign up on [OpenAI](https://openai.com/) and retrieve your API key.
2. **Go**: [Download and install Go](https://go.dev/doc/install).

## Setup

Before interacting with the OpenAI API, you need to set up your API key as an environment variable.

### Linux/macOS (bash/zsh)
```bash
export OPENAI_API_KEY="your_openai_api_key_here"
```

### Windows (Command Prompt)
```cmd
set OPENAI_API_KEY=your_openai_api_key_here
```

### Windows (PowerShell)
```powershell
$env:OPENAI_API_KEY="your_openai_api_key_here"
```

For permanent setup, add the environment variable to your shell's profile file (`~/.bashrc`, `~/.zshrc`, etc.) or system environment variables on Windows.

## Steps

1. **Set up your OpenAI API Key**: Follow the setup instructions above to configure your API key.

2. **Run the example**: Execute the following command:

```shell
go run github.com/tmc/langchaingo/examples/openai-completion-example@main
```

You should see output similar to the following:

```shell
The first man to walk on the moon was Neil
```

Congratulations! You have successfully built and executed your first LangChainGo LLM-backed program using OpenAI's cloud-based inference.


Here is the entire program (from [openai-completion-example](https://github.com/tmc/langchaingo/blob/main/examples/openai-completion-example/openai_completion_example.go)):

<CodeBlock language="go">{ExampleOpenAI}</CodeBlock>


